<?php
session_start();
require('check_login.php');
include(dirname(__FILE__) . '/config.php');
require('header.php');
require_once('contacts_lib.php');
require_once('emails_lib.php');
require_once('util.php');
$upcomming_birthdays=get_contacts_birthday_notif(7);
?>
<!-- BEGIN CONTAINER -->
<div class="page-container">
	<!-- BEGIN SIDEBAR -->
	<?php require_once('left_menu.php'); ?>
	<!-- END SIDEBAR -->
	<!-- BEGIN CONTENT -->
	<div class="page-content-wrapper">
		<div class="page-content">
			<!-- /.modal -->
			<!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->
			<!-- BEGIN STYLE CUSTOMIZER -->
			
			<!-- END STYLE CUSTOMIZER -->
			<!-- BEGIN PAGE HEADER-->
			<div class="row">
				<div class="col-md-12">
					<!-- BEGIN PAGE TITLE & BREADCRUMB-->
					<ul class="page-breadcrumb breadcrumb">
						<li>
							<i class="fa fa-home"></i>
							<a href="index.php">
								Trang chủ
							</a>
							<i class="fa fa-angle-right"></i>
						</li>
						<li>
							<a href="#">
								Màn hình quản trị
							</a>
						</li>
						
					</ul>
					<!-- END PAGE TITLE & BREADCRUMB-->
				</div>
			</div>
			<!-- END PAGE HEADER-->
			<!-- BEGIN PAGE CONTENT-->
			<div class="row">
				<div class="col-md-12">
					<!-- BEGIN EXAMPLE TABLE PORTLET-->
					<div class="portlet box green">
						<div class="portlet-title">
							<div class="caption">
								<i class="fa fa-cogs"></i>Sinh nhật khách hàng
							</div>
							
						</div>
						<div class="portlet-body">
							<form action="send_mail_birthday_alert.php" method="post">
							<table class="table table-striped table-bordered table-hover" id="upcomming_birthday_list">
							<thead>
							<tr>
							
							<th class="table-checkbox">
									<input type="checkbox" class="group-checkable" data-set="#upcomming_birthday_list .checkboxes"/>
								</th>
								<th>
									 Họ và Tên
								</th>
								<th>
									 Email
								</th>
								
								<th>
									 Ngày sinh
								</th>
								
								<th>
									 Ngày gửi gần nhất
								</th>
								<th>
									 Tình trạng
								</th>
							</tr>
							</thead>
							<tbody>
							
							<?php foreach ($upcomming_birthdays as $upcomming_birthday){?>
							<tr>
								<td>
									<input type="checkbox" name="id[]" class="checkboxes" value="<?php echo $upcomming_birthday['id']?>"/>
								</td>
								<td>
									 <?php echo $upcomming_birthday['first_name']." ".$upcomming_birthday['last_name']  ?>
								</td>
								<td>
									 <?php echo $upcomming_birthday['email']?>
								</td>
								
								<td>
									 <?php echo $upcomming_birthday['birth_day']?>
								</td>
								<td>
									 <?php 
									 $log=get_latest_email_log(null,$upcomming_birthday['email']);
									 echo make_readable_time($log['date_sent']);
									 ?>
								</td>
								<td>
									 <?php 
									 $log=get_latest_email_log(null,$upcomming_birthday['email']);
									 if($log['sent_status']==1){
									 ?>
									 <span class="label label-sm label-success">
											 Đã gửi thành công
									 </span>
									 <?php 
									 }
									 else{
									 ?>
									 <span class="label label-sm label-danger">
											 Bị lỗi
										</span>
									 <?php 
									 }
									 
									 ?>
								</td>
							</tr>
							<?php }?>
							
							
							
								
							</tbody>
							</table>
							<div class="row">
								
								<div class="btn-group pull-right col-sm-12">
									<input id="send_all_birthday" type="submit" class="btn green" name="go" value="Gửi email"/>
									 
									
								</div>
								</form>
							</div>
						</div>
						
					</div>
					<!-- END EXAMPLE TABLE PORTLET-->
				</div>
			</div>
			
			<!-- END PAGE CONTENT-->
		</div>
	</div>
	<!-- END CONTENT -->
</div>
<!-- END CONTAINER -->
<!-- BEGIN FOOTER -->
<?php 
require_once('footer.php');
require_once('common_script.php');
?>

<!-- BEGIN PAGE LEVEL SCRIPTS -->
<script src="assets/scripts/core/app.js"></script>
<script src="js/dashboard.js"></script>
<script>
jQuery(document).ready(function() {       
   App.init();
   TableManaged.init();
});
 
</script>
</body>
<!-- END BODY -->
</html>